package com.pesilo.module.navigate.mvc.view.component
{
	import com.pesilo.base.BaseComponent;
	import com.pesilo.module.navigate.mvc.controller.ApplicationFacade;
	import com.pesilo.module.navigate.mvc.model.CookiesProxy;
	import com.pesilo.util.Logger;
	import com.pesilo.util.UIUtil;
	import com.ui.pesilo.module.ui.NavigatePanel;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import org.puremvc.as3.multicore.interfaces.IProxy;
	import org.puremvc.as3.multicore.patterns.facade.Facade;

	public class NavigateComponent extends BaseComponent
	{
		private var mc:Sprite;
		private var navigatePanel:NavigatePanel;
		private var bg:Sprite;
		private var weather:MovieClip;
		private var settingBtn:Sprite;
		private var praiseBtn:MovieClip;
		private var cook:CookiesProxy;
		private var backBtn:Sprite;
		private var registerBtn:Sprite;
		private var loginBtn:Sprite;
		
		public function NavigateComponent()
		{
			super();
		}
		
		override public function initUI():void{
			mc=new Sprite();
			this.addChild(mc);
			
			navigatePanel=new NavigatePanel();
			mc.addChild(navigatePanel);
			
			bg=UIUtil.getElement(navigatePanel,"bg")as Sprite;
			weather=UIUtil.getElement(navigatePanel,"weather")as MovieClip;
			settingBtn=UIUtil.getElement(navigatePanel,"settingBtn")as Sprite;
			praiseBtn=UIUtil.getElement(navigatePanel,"praiseBtn")as MovieClip;
			backBtn=UIUtil.getElement(navigatePanel,"backBtn")as Sprite;
			registerBtn=UIUtil.getElement(navigatePanel,"registerBtn")as Sprite;
			loginBtn=UIUtil.getElement(navigatePanel,"loginBtn")as Sprite;
			
			weather.gotoAndStop(1);
			praiseBtn.buttonMode=true;
			backBtn.buttonMode=true;
			backBtn.visible=false;
			registerBtn.buttonMode=true;
			loginBtn.buttonMode=true;
			
			cook=Facade.getInstance(ApplicationFacade.NAME).retrieveProxy(CookiesProxy.NAME)as CookiesProxy;
			if(cook.checkPraise()){
				praiseBtn.gotoAndStop(2);
			}else{
				praiseBtn.gotoAndStop(1);
			}
		}
		
		/**
		 * 返回按钮
		 */
		public function backState(b:Boolean=false):void{
			backBtn.visible=b;
			if(b){
				
			}else{
			}
		}
		
		/**
		 * 设置天气
		 */
		public function setWeather(type:int):void{
			if(weather){
				weather.gotoAndStop(type);
			}
		}
		
		override public function initEvent(b:Boolean=true):void{
			if(b){
				praiseBtn.addEventListener(MouseEvent.CLICK,__praiseClickHandle);
			}
		}
		
		protected function __praiseClickHandle(e:MouseEvent):void
		{
			if(!cook.checkPraise()){
				cook.praised();
				praiseBtn.gotoAndStop(2);
				Logger.logInfo("Praise clicked!");
			}
		}		
		
		override public function initLocation():void{
			bg.width=stage.stageWidth;
			
			backBtn.x=stage.stageWidth-36;
			praiseBtn.x=stage.stageWidth-36;
			settingBtn.x=backBtn.x-36;
			weather.x=settingBtn.x-30;
			registerBtn.x=weather.x-54;
			loginBtn.x=registerBtn.x-45;
		}
	}
}